PACKAGE=makeczech
VERSION := $(shell rpm -q --qf '%{version}\n' --specfile $(PACKAGE).spec | head -1)
RELEASE := $(shell rpm -q --qf '%{release}\n' --specfile $(PACKAGE).spec | head -1)
ARCHIVEVER := $(VERSION)-$(shell date +%Y%m%d)

BINDIR      := /usr/bin/
RPM=$(HOME)/rpm

PRODUCT      = "PCLinuxOS 2007"
export PRODUCT

MSGFMT       = $(BINDIR)/msgfmt


bindir=$(prefix)/usr/sbin/
sharedir=$(prefix)/usr/share/$(PACKAGE)/

INSTBINS := ${patsubst bin/%,bin/%.inst,${wildcard bin/*}}
MOS := ${patsubst po/%.po,mo/%.mo,${wildcard po/*.po}}
INSTMOS := ${patsubst %.mo,%.moinst,$(MOS)}
#MOS_OW := ${patsubst po_ow/%.po,mo_ow/%.mo,${wildcard po_ow/*.po}}
#INSTMOS_OW := ${patsubst %.mo,%.moinst,$(MOS_OW)}
.PHONY: all clean po

all: targetdirs $(MOS)

targetdirs:
	if [ ! -d mo ]; then mkdir mo; fi
#	if [ ! -d mo_ow ]; then mkdir mo_ow; fi

mo/%.mo: po/%.po
	$(MSGFMT) -o $@ $<
	

#mo_ow/%.mo: po_ow/%.po
#	$(MSGFMT) -o $@ $<



installdirs:
	install -d $(sharedir)/tree/usr/share/locale/cs_CZ/LC_MESSAGES
#	install -d $(sharedir)/tree/usr/share/locale/cs/LC_MESSAGES
	install -d $(bindir)
	install -d $(prefix)/etc/makeczech
	install -d $(prefix)/usr/share/doc/HTML/

install: all installdirs $(INSTMOS) $(INSTMOS_OW) $(INSTBINS)
	cp -p -Rf share/* $(sharedir)
	cp -p -Rf etc/* $(prefix)/etc/
	cp -p -Rf help/* $(prefix)/usr/share/doc/HTML/
	
mo/%.moinst: mo/%.mo
	install -m 644 $< $(sharedir)/tree/usr/share/locale/cs_CZ/LC_MESSAGES/

#mo_ow/%.moinst: mo_ow/%.mo
#	install -m 644 $< $(sharedir)/tree/usr/share/locale/cs/LC_MESSAGES/

bin/%.inst : bin/%
	install -m 755 $< $(bindir)

clean:
	rm -Rf mo

cleandist:
	rm -rf $(PACKAGE)-$(ARCHIVEVER) $(PACKAGE)-$(ARCHIVEVER).tar.bz2

distdir:
	if [ ! -d $(PACKAGE)-$(VERSION) ]; then mkdir $(PACKAGE)-$(VERSION); fi

localcopy: clean distdir
	tar cp --exclude=.svn --exclude=$(PACKAGE)-$(VERSION) --exclude=*.tar.bz2  . | tar xp -C $(PACKAGE)-$(VERSION)
	
tar: localcopy cleandist
	tar cjvf $(PACKAGE)-$(ARCHIVEVER).tar.bz2 $(PACKAGE)-$(VERSION)
	rm -rf $(PACKAGE)-$(VERSION)

rpm: tar
	rpmbuild -ta $(PACKAGE)-$(ARCHIVEVER).tar.bz2

rpm-install: rpm
	rpm -Uvh --force /usr/src/rpm/RPMS/i586/$(PACKAGE)-$(VERSION)-$(RELEASE).i586.rpm

gupload:
	gupload /usr/src/rpm/RPMS/i586/$(PACKAGE)-$(VERSION)-$(RELEASE).i586.rpm "Utility to make PCLinuxOS installation speaking czech"

upload:
	scp `rpm --eval '%_rpmdir'`/i586/$(PACKAGE)-$(VERSION)-$(RELEASE).i586.rpm dsmid@oko.clever.cz:www/pclinuxos/2007/RPMS.czech
	scp `rpm --eval '%_srcrpmdir'`/$(PACKAGE)-$(VERSION)-$(RELEASE).src.rpm dsmid@oko.clever.cz:www/pclinuxos/2007/SRPMS.czech
	ssh dsmid@oko.clever.cz www/pclinuxos/2007/regenerate
